﻿using System;
using Himah.IntegrationTests;
using NUnit.Framework;

namespace IrishSettings.IntegrationTests.SettingsValuesTests
{
    [TestFixture]
    public class CachedSettingsTests
    {

        //Depends on Reset
        [SetUp]
        public void SetUpFixture()
        {
            IrishSettingsManager hsm = new IrishSettingsManager(SchemaUtils.CreateSampleSchema());
            hsm.Reset();
        }

        [Test]
        public void GetCurrentVersionExpecingV1WithoutUpgrade()
        {
            //Defaults
            IrishSettingsManagerCached hsm = new IrishSettingsManagerCached(SchemaUtils.CreateSampleSchema(), new FakeCache());
            //Save or we won't get anything.
            hsm.Save();
            Assert.AreEqual("en-US",hsm["culture"].Value.ToString());
            Assert.AreEqual(new Version(1, 0).ToString(), hsm.VersionCurrent().ToString());
        }

        



        [Test]
        public void CheckDbClear()
        {
            //Defaults
            IrishSettingsManagerCached hsm = new IrishSettingsManagerCached(SchemaUtils.CreateSampleSchema(), new FakeCache());
            hsm.Reset();
            Assert.AreEqual("en-US", hsm["culture"].Value.ToString());
        }


        [Test]
        public void CheckADefault()
        {
            //Defaults
            IrishSettingsManagerCached hsm = new IrishSettingsManagerCached(SchemaUtils.CreateSampleSchema(), new FakeCache());
            Assert.AreEqual("en-US",hsm["culture"].Value.ToString());
        }

        [Test]
        public void ClearLoadChange()
        {
            //Defaults
            TestSettings schema = SchemaUtils.CreateSampleSchema();
            IrishSettingsManagerCached hsm = new IrishSettingsManagerCached(schema, new FakeCache());
            Assert.AreEqual("en-US",hsm["culture"].Value.ToString());
            hsm["culture"].Value = "is-is";
            hsm.Save();
            //Reload mgr
            hsm = new IrishSettingsManagerCached(schema, new FakeCache());
            Assert.AreEqual("is-is",hsm["culture"].Value.ToString());
        }

    }
}
